package com.tarena.luban.demo.rocket.controller;

import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TransController {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @GetMapping("/half/send")
    public String halfSend(String msg){
        //发送消息,封装一个消息对象
        Message<String> message = MessageBuilder.withPayload(msg).build();
        //desitination 目标地址 topic名称 + tags过滤标签
        //message 发送的消息
        //obj 本地事务处理的业务数据
        rocketMQTemplate.
                sendMessageInTransaction("trans-topic",message,"你好");
        return "success";
    }
}
